package com.douqu.game.core.entity.ext.data.boon;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.entity.EntityObject;
import com.douqu.game.core.factory.DataFactory;

/**
 * @author: miracle.
 * Description: 竞拍记录
 * Date: 2018/3/21 0021 下午 4:40
 * Huan Yu Copyright (c) 2017 All Rights Reserved.
 */
public class AuctionRecord extends EntityObject {

    /**
     * 竞拍id
     */
    private int auctionBeanId;

    /**
     * 竞拍时间
     */
    private long auctionTime;

    /**
     * 成功失败 true表示最高价是我出的 false表示不是
     */
    private boolean success;

    /***
     * 是否结束 true 结束  false 未结束
     */
    private boolean isEnd;

    public AuctionRecord(){

    }

    public AuctionRecord(int auctionBeanId,boolean success){
        this.auctionBeanId = auctionBeanId;
        this.success = success;
        this.auctionTime = DataFactory.currentTime;
    }
    public void writeTo(ByteBuffer buffer){
        buffer.writeInt(auctionBeanId);
        buffer.writeLong(auctionTime);
        buffer.writeBoolean(success);
        buffer.writeBoolean(isEnd);
    }

    public void loadFrom(ByteBuffer buffer){
        auctionBeanId = buffer.readInt();
        auctionTime = buffer.readLong();
        success = buffer.readBoolean();
        isEnd = buffer.readBoolean();
    }
    public int getAuctionBeanId() {
        return auctionBeanId;
    }

    public void setAuctionBeanId(int auctionBeanId) {
        this.auctionBeanId = auctionBeanId;
    }

    public long getAuctionTime() {
        return auctionTime;
    }

    public void setAuctionTime(long auctionTime) {
        this.auctionTime = auctionTime;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public boolean isEnd() {
        return isEnd;
    }

    public void setEnd(boolean isEnd) {
        this.isEnd = isEnd;
    }

    @Override
    public String toString() {
        return "AuctionRecord{" +
                "auctionBeanId=" + auctionBeanId +
                ", auctionTime=" + auctionTime +
                ", success=" + success +
                ", isEnd=" + isEnd +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        AuctionRecord that = (AuctionRecord) o;
        /**
         * 只要拍卖的同一个物品表示 是一个类
         */
        if (auctionBeanId != that.auctionBeanId) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return auctionBeanId;
    }


}
